package com.dhcc.bpm.modules.sandbox.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.modules.api.service.IApiService;
import com.dhcc.bpm.modules.sandbox.entity.OpcCaseLog;
import com.dhcc.bpm.modules.sandbox.service.IOpcCaseLogService;
import com.dhcc.bpm.modules.sandbox.service.IReturnCodeService;
import com.dhcc.bpm.modules.sandbox.vo.OpcCaseLogVO;
import com.dhcc.bpm.modules.sandbox.vo.ReturnCodeVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 沙箱用例记录表 控制器
 *
 * @author xiafayu
 * @since 2022-04-06
 */
@RestController
@AllArgsConstructor
@RequestMapping("cbus-bpm-boot/opccaselog")
@Api(value = "沙箱用例记录表", tags = "沙箱用例记录表接口")
public class OpcCaseLogController extends BladeController {

    private IApiService apiService;
    private IOpcCaseLogService opcCaseLogService;
    private IReturnCodeService returnCodeService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入opcCaseLog")
    public R<OpcCaseLog> detail(OpcCaseLog opcCaseLog) {
        OpcCaseLog detail = opcCaseLogService.getOne(Condition.getQueryWrapper(opcCaseLog));
        return R.data(detail);
    }

    /**
     * 分页 沙箱用例记录表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入opcCaseLog")
    public R<IPage<OpcCaseLog>> list(OpcCaseLog opcCaseLog, Query query) {
        IPage<OpcCaseLog> pages = opcCaseLogService.page(Condition.getPage(query), Condition.getQueryWrapper(opcCaseLog));
        return R.data(pages);
    }

    /**
     * 自定义分页 沙箱用例记录表
     */
    @GetMapping("/page")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "分页", notes = "传入opcCaseLog")
    public R<IPage<ReturnCodeVO>> page(OpcCaseLogVO opcCaseLog, Query query) {
        IPage<ReturnCodeVO> pages = returnCodeService.selectOpcCaseLogPage(Condition.getPage(query), opcCaseLog);
        return R.data(pages);
    }

    /**
     * 新增 沙箱用例记录表
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入opcCaseLog")
    public R save(@Valid @RequestBody OpcCaseLog opcCaseLog) {
        return R.status(opcCaseLogService.save(opcCaseLog));
    }

    /**
     * 修改 沙箱用例记录表
     */
    @PostMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入opcCaseLog")
    public R update(@Valid @RequestBody OpcCaseLog opcCaseLog) {
        return R.status(opcCaseLogService.updateById(opcCaseLog));
    }

    /**
     * 新增或修改 沙箱用例记录表
     */
    @PostMapping("/submit")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "新增或修改", notes = "传入opcCaseLog")
    public R submit(@Valid @RequestBody OpcCaseLog opcCaseLog) {
        return R.status(opcCaseLogService.saveOrUpdate(opcCaseLog));
    }


    /**
     * 删除 沙箱用例记录表
     */
    @PostMapping("/remove")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(opcCaseLogService.removeByIds(Func.toLongList(ids)));
    }


}
